package com.swingson.properties.impl;

import com.swingson.SwingsonGui;
import com.swingson.jsonparser.JsonElement;
import com.swingson.other.IconLoader;
import com.swingson.properties.AnchoredPropertyProcessor;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JComponent;

/**
 * @author sad
 */
public class IconPropertyProcessor extends AnchoredPropertyProcessor {

    @Override
    protected Object getValue(JsonElement jsonElement, JComponent component, SwingsonGui gui, String propertyName) {
        AbstractButton button = (AbstractButton) component;
        String value = jsonElement.getAsString();
        IconLoader loader = new IconLoader();
        Icon icon = loader.loadImage(value, gui);
        button.setIcon(icon);
        return null;
    }
}
